/**
 * 分页对象核心js
 * @wu.i
 */
var qryPager;
(function(scope) {
	var PageTpl = Base.extend({
		constructor : function(attribute) {
			attribute= attribute || {};
			this.set_attr(attribute);
			this.def_page_size =10;
			this.param = {"page_size":attribute['page_size'] || this.def_page_size}
		},
		set_attr:function(attribute){
			attribute= attribute || {};
			this.tplLi = attribute.clone_elt|| "comment_li_tpl";
			
			this.tplUlId = attribute.clone_scope || "ul_lists";
			this.tplEle = attribute.clone_scope_Jq;
			this.page_nav =attribute.page_nav || 'pageNav';
			this.clone_elt_type=attribute.clone_elt_type || "li";
			this.qry_scope_id =attribute['qry_scope_id'] || '';
		},
		getParam :function(){ //获取参数
//			var p_param =commonJS.getInputDomain(this.qry_scope_id); //组装参数
//			jQuery.extend(this.param,p_param);
			return this.param;
		},
		setParam : function(currJq,json_data) {
			jQuery.extend(this.param, json_data);
		},
		query_info : function(t_param) {
			var param = this.getParam(), me = this;
			if(t_param){
				jQuery.extend(param, t_param);
			}
//			if (!qryPager) {
//				var pager = new Pager(this.page_nav,this.param["service_name"],this.param.method, false, [param],
//						function(reply) {
//							me.render_info(reply);
//						}, false, false, false, null, 'simple', false);
//				window.qryPager = pager;
//			} else {
//				window.qryPager.setParam(param);
//				param.page_index = 1;
//				window.qryPager.doService(param);
//			}
			
			//ajax调用接口再调用me.render_info(reply);
//			var reply={};
//			var list1=new Array();
//			list1.push({note_id:1,note_title:'title',note_content:'note_content'});
//			list1.push({note_id:2,note_title:'title2',note_content:'note_content2'});
////			alert("ajax调用接口再调用me.render_info(reply);");
//			reply.list=list1;
			
			
//			 $.post("http://peaceful-tor-4422.herokuapp.com/users", null, function(reply) {
//			        if (reply) {
//			        	me.render_info(reply);
//			        }
//			    },'json');
			 
			 $.getJSON("/AntsProject/data/data1.html",     
	                    function(reply){  
						 if (reply) {
					        	me.render_info(reply);
					     }
	                }); 
			
//			$.ajax({
//				  url :"http://peaceful-tor-4422.herokuapp.com/users?jsoncallback=?",
//				  type: "GET",
//				    dataType: "jsonp",
//				    jsonp: "jsonpCallback",
//				    crossDomain : true,
//				   
//				    success: function (reply){
//				    	if (reply) {
//				        	me.render_info(reply);
//				     }
//				    },
//				       error: function(xhr){
//				        alert(xhr+"请求出错(请检查相关度网络状况.)");
//				    }
//				}
//				);
			 
//			 在服务端通过获得callback参数(如：jsonp*****)得到jQuery端随后要回调的 
//			    然后返回类似:"jsonp*****("+要返回的json数组+")"; 
//			    jquery就会通过回调方法动态加载调用这个:jsonp*****(json数组); 
//			    这样就达到了跨域数据交换的目的.
			 
//			 $.get("http://peaceful-tor-4422.herokuapp.com/users?jsoncallback=?" ,function(response,status,xhr) {  
//	              alert(response);  
//	              alert(status);  
//	              alert(xhr);  
//	          });  
			
		},
		render_info : function(reply) {
			var me = this;
			if(typeof(this.render_info_before) =="function")
				this.render_info_before();
		
			if (reply)
			{
				this.gettplUl().children(this.clone_elt_type+":gt(0)").remove();
				for (var i = 0, liData; liData = reply.list[i++];) {
					this.bind_event(liData,i);
				}
			} else 
			{
				this.gettplUl().children(this.clone_elt_type+":gt(0)").fadeIn("fast",function() {me.gettplUl().children(me.clone_elt_type + ":gt(0)").remove();})
			}
			this.after_data_handle(reply);
		},
		bind_event : function(jsonData,index) {
			var cloneLi = this.gettplLi().clone(), me = this;
			cloneLi.data("qry_data", jsonData || {});
			(function(cloneLi) {
				var qry_data = cloneLi.data("qry_data");
				me.gettplUl().append(cloneLi.attr("id", "").show());
				me.record_event(qry_data,cloneLi,index);
				
			}(cloneLi));
		},
		record_event:function(qry_data,cloneLi){},////TODO 子类实现}
		after_data_handle:function(reply){},////TODO 子类实现}
		gettplUl:function(){
			return this.tplEle || $("#"+this.tplUlId);
		},
		gettplLi:function(){
			return $("#"+this.tplLi);
		},
		resetValues:function(){//重置所有值
			$("[fieldType='db'][type!='radio']").val("");
		}

	})
	window.PageTpl =PageTpl;
}(window));


